import { App, ConfigProvider, theme } from 'antd';
import { EmptyData, themeConfig, ThemeMode, useComponentClass } from '@ycx/ui';
import React, { PropsWithChildren } from 'react';
import zhCN from 'antd/locale/zh_CN';
import { useTheme } from '@/store/settingsStore.ts';

const AntConfig: React.FC<PropsWithChildren> = ({ children }) => {
  const themeMode = useTheme();
  const componentClass = useComponentClass();
  const algorithm = themeMode === ThemeMode.Light ? theme.defaultAlgorithm : theme.darkAlgorithm;

  return (
    <ConfigProvider
      locale={zhCN}
      {...componentClass}
      renderEmpty={() => <EmptyData theme={themeMode} />}
      theme={{
        ...themeConfig[themeMode],
        algorithm: algorithm,
      }}
    >
      <App message={{ top: 64 }}>{children}</App>
    </ConfigProvider>
  );
};

export default AntConfig;
